// Justin Cowen
// CSC 332 - Data Structures
// Program #1
// This program will implement the Box class and its various methods. 
// The Box class will incorporate a makeEmpty method, an isEmpty method, 
// an add method, a remove method, and a print method. 

class Box <T>{
    //Data Fields
    private T[] array; // the collection
    private int currentSize;  // current size ofthe collection
    static final int DEFAULT_SIZE = 10;

    // Default constructor
    public Box(){
        this (DEFAULT_SIZE);
    }

    // Constructor
    public Box(int maxSize){
        array = (T[]) new Object[maxSize];
        currentSize = 0;
    }

    //Implementation of public methods

    // the makeEmpty method is a loop that will clear the array of all
    // objects, set each object as null, and set currentSize to 0
    public void makeEmpty(){
        for(int i=0; i<currentSize; i++){
            array[i]=null;
        }
        currentSize = 0;
    }

    // the isEmpty method returns a boolean value that determines 
    // whether or not the array contains any values. 
    public boolean isEmpty(){
        if(currentSize==0)
            return true;
        else
            return false;
    }

    // the add method adds the object passed to it into the array at 
    // the current index
    public void add(T x){
        array[currentSize]= x;
        currentSize++;
    }

    // the remove method eliminates the final object in the array, 
    // sets the final object in the array to null, decrements the 
    // size of the array, and returns the value which has been 
    // deleted
    public T remove(){
        currentSize = currentSize-1;
        T temp = array[currentSize];  // temporary object to return
        array[currentSize] = null;
        return temp;
    }

    // the print method prints out each object in the array to 
    // the screen
    public void print(){
        for(int i=0; i<currentSize; i++){
            System.out.println(array[i]);
        }
    }
}   // end Box

class Prog1{
    public static void main(String[] args){
        Box<Integer> b = new Box<Integer>();

        //Testing of methods from Box using b 
        System.out.println("Using b.add, added the values 10, 20, 30, 40, 50 ");
        b.add(10);
        b.add(20);
        b.add(30);
        b.add(40);
        b.add(50);
        System.out.println("");
        System.out.println("Current b.print method after adding 5 objects: ");
        b.print();
        System.out.println("");
        System.out.println("Using b.remove, remove one value from array");
        int tempRemove = b.remove();   // temporary value to be removed
        System.out.println("Value to be removed: "+tempRemove);
        System.out.println("");
        System.out.println("b.print method after removing 1 objects:");
        b.print();
        System.out.println("");
        System.out.println("Current value of isEmpty command: "+b.isEmpty());
        b.makeEmpty();
        System.out.println("makeEmpty method then called");
        System.out.println("Value of isEmpty after makeEmpty is called: "+b.isEmpty());
        System.out.println("");
        System.out.println("Print out array of after makeEmpty: ");
        b.print(); 
	System.out.println("");
        System.out.println("End of Program");
    }
} 

